package com.yeung.exam;

import java.util.ArrayList;
import java.util.Scanner;

/*
3
0 4 0
4 0 0
0 0 0
 */
public class 豆油瓶 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] mat = new int[n][n];
        int index = 0;
        while (index < n) {
            for (int i = 0; i < n; i++) {
                mat[index][i] = sc.nextInt();
            }
            index++;
        }
        //开始计算
        ArrayList<Integer>[] realtion = new ArrayList[n];//记录用户i与那些人交互过(>3)
        //初始化
        for (int i = 0; i < realtion.length; i++) {
            realtion[i] = new ArrayList<>();
        }

        for (int i = 0; i < n; i++) {
            for (int k = i; k < n; k++) {//只计算上三角 对称的
                if (i != k) {
                    //不是自己和自己
                    if (mat[i][k] >= 3) {
                        realtion[i].add(k);
                    }
                }

            }
        }
//        遍历交互信息数组
        int[] group = new int[n];
        int count = 0;
        for (int i = 0; i < realtion.length; i++) {
            if (group[i] == 0) {
                //表示未分组, 值为几,分的就是第几组
                group[i] = ++count;
            }
            ArrayList reas = realtion[i];
            //与该用户有交互的用户也分为同一组
            for (Object rea : reas) {
                int user = (int) rea;
                if (group[user] == 0)
                    group[user] = group[i];
            }
        }
        System.out.println(count);
    }
}
